﻿package java_异常4;

public class Person {
	private String name;
	private int age;
	private String sex;
    
	public void setSex(String sex) throws Exception{
		if("男".equals(sex)||"女".equals(sex)){
			this.sex=sex;
		}else{
			throw new Exception("性别必须是\"男\"或者\"女\"!");
		}
	}
	public void setAge(int age) throws Exception{
		if(age>=1&&age<=22){
			this.age=age;
		}else{
			throw new  Exception("年龄必须在1~22之间!");
		} 
	}
	public void print(){
		System.out.println(this.name+"("+this.sex+","+this.age+"岁)");
	}
}